/***
 * Copyright (c) 2021-2031 murenchao
 * fig is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *       http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package cool.taomu.software.fig.mqtt.broker

import cool.taomu.software.fig.classloader.FigClassLoaderManage.Autowired
import cool.taomu.software.fig.mqtt.broker.impl.request.MQTTConnect
import cool.taomu.software.fig.mqtt.broker.impl.request.MQTTDisconnect
import cool.taomu.software.fig.mqtt.broker.impl.request.MQTTPublish
import cool.taomu.software.fig.mqtt.broker.impl.request.MQTTSubscribe
import io.netty.handler.codec.mqtt.MqttMessageType
import java.util.HashMap
import java.util.Map
import org.eclipse.xtend.lib.annotations.Accessors
import cool.taomu.software.fig.mqtt.broker.impl.request.MQTTPubAck
import cool.taomu.software.fig.mqtt.broker.impl.request.MQTTPubComp
import cool.taomu.software.fig.mqtt.broker.impl.request.MQTTPubRec
import cool.taomu.software.fig.mqtt.broker.impl.request.MQTTPubRel
import cool.taomu.software.fig.mqtt.broker.impl.request.MQTTPingEq
import cool.taomu.software.fig.mqtt.broker.inter.IRequest

/**
 * 名字 	|	值 	|	报文流动方向	|	描述
 * Reserved	|	0 	|	禁止 			|	保留
 * CONNECT  V	|	1 	|	客户端到服务端 	| 	客户端请求连接服务端 
 * CONNACK  V	|	2 	|	服务端到客户端 	| 	连接报文确认
 * PUBLISH 	|	3 	|	两个方向都允许 	|	发布消息
 * PUBACK		|	4 	|	两个方向都允许	|	QoS 1 消息发布收到确认
 * PUBREC 		|	5 	|	两个方向都允许 	|	发布收到(保证交付第一步)
 * PUBREL		|	6 	|	两个方向都允许 	|	发布释放(保证交付第二步)
 * PUBCOMP 	|	7 	|	两个方向都允许 	|	QoS 2 消息发布完成(保证交付第三步)
 * SUBSCRIBE V	|	8 	|	客户端到服务端 	|	客户端订阅请求
 * SUBACK 	  V	|	9 	|	服务端到客户端 	|	订阅请求报文确认
 * UNSUBSCRIBE |	10 	|	客户端到服务端 	|	客户端取消订阅请求
 * UNSUBACK 	|	11 	|	服务端到客户端 	|	取消订阅报文确认
 * PINGREQ  V	|	12 	|	客户端到服务端 	|	心跳请求
 * PINGRESP V	|	13 	|	服务端到客户端 	|	心跳响应
 * DISCONNECT 	|	14 	|	两个方向都允许	|	断开连接通知
 * AUTH 		|	15 	|	两个方向都允许 	|	认证信息交换 mqttv5
 */
@Accessors
class MQTTConfig {
	Map<String, IRequest> mqttTypes = new HashMap<String, IRequest>();
	boolean isInit = false;
	@Autowired
	MQTTConnect connect;
	@Autowired
	MQTTSubscribe subscribe;
	@Autowired
	MQTTPingEq pingeq;
	@Autowired
	MQTTPublish publish;
	@Autowired
	MQTTPubAck puback;
	@Autowired
	MQTTPubRec pubrec;
	@Autowired
	MQTTPubRel pubrel;
	@Autowired
	MQTTPubComp pubcomp;
	@Autowired
	MQTTDisconnect disconnect;

	def init() {
		if (!isInit) {
			mqttTypes.put(MqttMessageType.CONNECT.name, connect);
			mqttTypes.put(MqttMessageType.SUBSCRIBE.name, subscribe);
			mqttTypes.put(MqttMessageType.PINGREQ.name, pingeq);
			// 两个方向都允许
			mqttTypes.put(MqttMessageType.PUBLISH.name, publish);
			mqttTypes.put(MqttMessageType.PUBACK.name, puback);
			mqttTypes.put(MqttMessageType.PUBREC.name, pubrec);
			mqttTypes.put(MqttMessageType.PUBREL.name, pubrel);
			mqttTypes.put(MqttMessageType.PUBCOMP.name, pubcomp);
			mqttTypes.put(MqttMessageType.DISCONNECT.name, disconnect);
			this.isInit = true;
		}
	}

}
